
export const getListData=(data)=>{
    return {
        type:"GETNEWS",
        data
    }
}


export function getNews(id,page){
    return dispatch=>{
        let curpage = (page)?page:1;
        let cateId = (id)?id:null;
        let url='http://localhost:3000/news/list';
        var params ={cateId:cateId,page:curpage,limit:4};
        return fetch(url,{
            method:'post',
            headers:{
                'Content-Type':'application/json'
            },
            body:JSON.stringify(params)
        })
        .then(res=>{
            return res.json()
        })
        .then((data)=>{
            dispatch(getListData(data));
        })
    }
}

export const getNewsCate=(data)=>{
    return {
        type:"GETNEWSCATE",
        data
    }
}

export function getCate(){
    return dispatch=>{
        var url='http://localhost:3000/cate/getnewschilren';
        return fetch(url)
        .then(res=>{
            return res.json()
        })
        .then((data)=>{
            dispatch(getNewsCate(data));
        })
    }
}
